//
//  ViewController.m
//  gifViewDemo
//
//  Created by jinyu on 16/9/13.
//  Copyright © 2016年 jinyu. All rights reserved.
//

#import "ViewController.h"
#import "GifView.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
// 第一种方法   UIImage动画数组
    
    [self showImageView];
    
// 第二种方法   UIwebView

    [self showWebView];
    
// 第三种方法    GifView
    
    [self showGifView];
    
    
}

-(void)showImageView{
    
    UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 100, 100)];
    [self.view addSubview: imageView];
    
    
    NSMutableArray * imageArr = [[NSMutableArray alloc]init];
    
    for(int i = 0;i < 6;i++){
        UIImage * image = [UIImage imageNamed:[NSString stringWithFormat:@"clock0%d.png",i+1]];
        
        [imageArr addObject:image];
    }
    
    //把存有UIImage的数组赋给动画图片数组
    imageView.animationImages = imageArr;
    //设置执行一次完整动画的时长
    imageView.animationDuration = 6*0.15;
    //动画重复次数 （0为重复播放）
    imageView.animationRepeatCount = 0;
    //开始播放动画
    [imageView startAnimating];
    //停止播放动画  - (void)stopAnimating;
    //判断是否正在执行动画  - (BOOL)isAnimating;
    
}
-(void)showWebView{
    
  
    //创建一个webView，添加到界面
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(20, 150, 200, 200)];
    [self.view addSubview:webView];
    //自动调整尺寸
    webView.scalesPageToFit = YES;
    //禁止滚动
    webView.scrollView.scrollEnabled = NO;
    //设置透明效果
    webView.backgroundColor = [UIColor clearColor];
    webView.opaque = 0;
    //加载数据
    [webView loadRequest:[[NSURLRequest alloc]initWithURL:[NSURL URLWithString:@"http://img4q.duitang.com/uploads/item/201411/24/20141124142427_ivHsz.gif"]]];

    
    
}
-(void)showGifView{
    
    NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://img4q.duitang.com/uploads/blog/201412/08/20141208103317_TGQL3.gif"]];
    GifView * gifview = [[GifView alloc]initWithFrame:CGRectMake(20, 300, 280, 100) data:data];
    [self.view addSubview: gifview];
    
    
}


//#pragma mark 播放动态图片方式3 第三方显示本地动态图片
//-(void)showGifImageMethodThree
//{
//    //方式一
//    //将图片转为NSData数据
//    NSData *localData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"1" ofType:@"gif"]];
//    //创建一个第三方的View显示图片
//    GifView *dataView = [[GifView alloc] initWithFrame:CGRectMake(0, 300, 200, 100) data:localData];
//    [self.view addSubview:dataView];
//    
//    //方式二
//    //得到图片的路径
//    NSString *path = [[NSBundle mainBundle] pathForResource:@"2" ofType:@"gif"];
//    GifView *dataView2 = [[GifView alloc] initWithFrame:CGRectMake(200, 300, 150, 100) filePath:path];
//    [self.view addSubview:dataView2];
//}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
